package edu.nuc.ahm.juc.add;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {




        // 总数是6
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <=6 ; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"Go out");
                countDownLatch.countDown();  // 数量 -1
            },String.valueOf(i)).start();
        }
        // 等待计数器归0 然后再向下执行
        countDownLatch.await();
        System.out.println("Close Door");
        // 假设这 六个学生都走完了
    }
}
